/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : ScreenSaver.c /Project:AVOS		       **
**        Revision : 1.0                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "ScreenSaverEvent.h"
#include "./win/NetmenuSetupEvent.h"

void SetScrSaverPalette(void)
{
    YUVENTRY mask_para[4] = {0,4095,4095,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 16392,0x8000 | 16408,0x8000 | 16408,16424,16424,16440,16440,16456,16456,16472,16472,16488,16488,16504,16504};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetScrSaverPos(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
        case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:	
            RECT NormalWindowRect = {276,158,226,158};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {1,{{276,158,226,158},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetScrSaverPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
        case OsdSize576i:
	 case OsdSize576p:
	 case OsdSize576iCVBS:	
            RECT NormalWindowRect1 = {276,158,226,158};
            pControl->winrect = NormalWindowRect1;
            CREATEWINDOWPARAM NormalWindowPara1= {1,{{276,158,226,158},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetScrSaverPalette};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara1);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlScrSaver(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
        case OsdSize480i:
	 case OsdSize480p:
	 case OsdSize480iCVBS:	
            CREATEWINDOWPARAM Normalwindow_para = {1,{{276,158,226,158},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetScrSaverPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","ScrSaver",WS_OVERLAPPEDWINDOW,
		                      276,158,226,158,NULL, (INT32S)&Normalwindow_para,NULL) ;
            pNewControl->win_id = 0 ;
            break ;
        case OsdSize576i:
	 case OsdSize576p:
	 case OsdSize576iCVBS:	
            CREATEWINDOWPARAM Normalwindow_para1 = {1,{{276,158,226,158},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetScrSaverPalette};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","ScrSaver",WS_OVERLAPPEDWINDOW,
		                      276,158,226,158,NULL, (INT32S)&Normalwindow_para1,NULL) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetScrSvrPos(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
       case OsdSize480i:
	case OsdSize480p:
	case OsdSize480iCVBS:	
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 150;
            pControl->winrect.height = 100;
            pControl->draw_info_num = 1;
            RECT NormalDrawRect[1] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,150,100},
            };
            for(iLoop=0; iLoop < 1; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
       case OsdSize576i:
	case OsdSize576p:
	case OsdSize576iCVBS:	
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 150;
            pControl->winrect.height = 100;
            pControl->draw_info_num = 1;
            RECT NormalDrawRect1[1] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,150,100},
            };
            for(iLoop=0; iLoop < 1; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect1[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S ScrSvrMsgProc(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_KEYDOWN:
            return ScrSvrOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlScrSvr(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- ScrSvr
    HWND *pNewControl;
    switch(CurOsdSize){
        case OsdSize480i:
	 case OsdSize480p:
	 case OsdSize480iCVBS:	
            pNewControl = AWCreateWinControl("TControl","ScrSvr",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,150,100,pParent,0,ScrSvrMsgProc) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 1;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[1] = {
                          {0,0,0,0,(INT32U)ICON_SCREEN_SAVE,DT_RLE_BMP_DATA}};
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
       case OsdSize576i:
	case OsdSize576p:
	case OsdSize576iCVBS:	
            pNewControl = AWCreateWinControl("TControl","ScrSvr",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,150,100,pParent,0,ScrSvrMsgProc) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 1;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas1[1] = {
                          {0,0,0,0,(INT32U)ICON_SCREEN_SAVE,DT_RLE_BMP_DATA}};
            memcpy(pNewControl->draw_info,NormalDrawDatas1, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuScrSaver(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pScrSaver = CreateControlScrSaver(NULL,CurrentOsdSize);
    SetScrSaverPos(pScrSaver,CurrentOsdSize);

    pNewControl= CreateControlScrSvr(pScrSaver,CurrentOsdSize);
    SetScrSvrPos(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pScrSaver;
    pWin->pFocusControl = AWFindWinCtrlByName("ScrSvr");
    return pScrSaver;
}

void WinResetScrSaverControlsPos(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://ScrSaver
            SetScrSaverPos(pControl,CurOsdSize) ;
            break ;
        case 1://ScrSvr
            SetScrSvrPos(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetScrSaverPos(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("ScrSaver");
    if(pControl == NULL) return ;

    WinResetScrSaverControlsPos(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetScrSaverPos(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

